#include "Particle.hpp"

#include <iostream>
using namespace std;

unsigned int Particle::ID_count = 0;
//ctor;
Particle::Particle() :
        x(0), y(0), x_speed(0), y_speed(0), rotation(0), rotation_speed(0), scale(1), mass(1)
{
    init();
}

Particle::Particle(float x, float y,
                   float x_speed, float y_speed,
                   float rotation, float rotation_speed,
                   float scale, float mass,
                   float dt_scale) :
        x(x), y(y), x_speed(x_speed), y_speed(y_speed), rotation(rotation), rotation_speed(rotation_speed), scale(scale), mass(mass), dt_scale(dt_scale), x_acceleration(0), y_acceleration(0), rotation_acceleration(0)
{
    init();
}

void Particle::init(){
    ID = ID_count++;
    #ifdef HARDDEBUG
    cout << "Created particle(" << ID << ")" << endl;
    output();
    #endif
}

//dstor
Particle::~Particle() {}

void Particle::update()
{
    const float dt_scaled = dt*dt_scale;

    x_speed += dt_scaled*x_acceleration;
    x += dt_scaled*x_speed;

    y_speed += dt_scaled*y_acceleration;
    y += dt_scaled*y_speed;

    rotation_speed += dt_scaled*rotation_acceleration;
    rotation += dt_scaled*rotation_speed;

    x_acceleration = y_acceleration = rotation_acceleration = 0;
}

void Particle::output()
{
#define out(x) cout << #x << ": " << x << endl
    out(ID);
    out(x);
    out(x_speed);
    out(x_acceleration);
    out(y);
    out(y_speed);
    out(y_acceleration);
    out(rotation);
    out(rotation_speed);
    out(rotation_acceleration);
    out(scale);
    out(mass);
    out(dt_scale);
#undef out
}

